// pages/export/export.js
import nami from '../../nami/index';
import utils from '../../utils/utils';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    diaryStr: '',
    weekStr: '',
    monthStr: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    nami.request({
      url: '/request/diary/showAll.groovy',
      success: function (res) {
        console.log(res);
        var diary = res.data.diary;
        var week = res.data.week;
        var month = res.data.month;
        var diaryStr = '日记' + '\n';
        var weekStr = '\n 周记' + '\n';
        var monthStr = '\n 月记' + '\n';
        for (let i = 0; i < diary.length; i++) {
          diaryStr = diaryStr + '\n' + diary[i].DATE + '\n';
          if (diary[i].WEEK != null) {
            diaryStr = diaryStr + '工作：' + diary[i].WEEK + '\n';
          }
          if (diary[i].HEALTH != null) {
            diaryStr = diaryStr + '健康：' + diary[i].HEALTH + '\n';
          }
          if (diary[i].FAMILY != null) {
            diaryStr = diaryStr + '家庭：' + diary[i].FAMILY + '\n';
          }
          if (diary[i].STUDY != null) {
            diaryStr = diaryStr + '学习：' + diary[i].STUDY + '\n';
          }
          if (diary[i].ANNIVERSARY != null) {
            diaryStr = diaryStr + '特殊日：' + diary[i].ANNIVERSARY + '\n';
          }
          if (diary[i].HOBBY != null) {
            diaryStr = diaryStr + '兴趣：' + diary[i].HOBBY + '\n';
          }
          if (diary[i].MONEY != null) {
            diaryStr = diaryStr + '金钱：' + diary[i].MONEY + '\n';
          }
          if (diary[i].RELATIONSHIP != null) {
            diaryStr = diaryStr + '人际关系：' + diary[i].RELATIONSHIP + '\n';
          }
          if (diary[i].PLAN != null) {
            diaryStr = diaryStr + '当日规划：' + diary[i].PLAN + '\n';
          }
        }

        for (let i = 0; i < week.length; i++) {
          weekStr = weekStr + '\n' + week[i].DATE + '\n';
          if (week[i].CONTENT != null) {
            weekStr = weekStr + week[i].CONTENT + '\n';
          }
        }

        for (let i = 0; i < month.length; i++) {
          monthStr = monthStr + '\n' + month[i].DATE + '\n';
          if (month[i].CONTENT != null) {
            monthStr = monthStr + month[i].CONTENT + '\n';
          } 
        }

        that.setData({
          diaryStr: diaryStr,
          weekStr: weekStr,
          monthStr: monthStr
        });
      }
    });
  },


})